import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'


//请求拦截器
//定义axios的拦截器
axios.interceptors.request.use(config=>{
    //axios请求信息
    let token= sessionStorage.getItem("token");
    config.headers['token']=token;
    // console.log(config.headers)
    //未来可以在请求头中存放token信息用于身份校验等。
    //一定要记得返回这个对象否则请求不会发出！！！
    return config;
});
// axios响应拦截器
axios.interceptors.response.use(res =>{
    // console.log(res);
    // if(res.data.code != 200 ){
    //     router.push({
    //        path: "/prompt",
    //         query: {
    //             message: res.data.msg
    //         }
    //     });
    // }
    return res.data;
})
//配置axios的全局路径
axios.defaults.baseURL = 'http://localhost:8080/';

const app = createApp(App);
// 全局挂载axios
app.config.globalProperties.$axios = axios;
// 挂载vuex
app.use(store);
app.use(router);
app.use(ElementPlus);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }
app.mount('#app');
